/*
 * @Description: 
 * @Author: zyj
 * @Date: 2022-05-27 17:12:49
 * @LastEditors: zyj
 * @LastEditTime: 2022-05-27 17:12:59
 */
/* AOP编程 */
Function.prototype.before = function (beforeFn) {
  let self = this;
  return function (...args) {
    let p = beforeFn();
    p.then((data) => {
      console.log(data);
      self.call(this, ...args)
    });


  }
}


function update() {
  console.log(this.name + "更新了数据");
}


let name = "window";


let obj = {
  name: "张三",
}


obj.fn = update.before(() => {
  console.log("函数之前执行");
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(100);
    }, 3000)
  });
})


obj.fn()